<?php
/*
+---------------------------------------------------------------+
| for e107Shop 1.2.X by http://e107.ir Persian e107 Support     |
| Creators : Persian e107 support and Webdoktor (NL)            |
| Bugfixed and streamlined by Bieleke (e107shop.com)            |
+---------------------------------------------------------------+
*/
$scriptDebug = false;
require_once('e107shop_folder.php');
require(e_PLUGIN.E107SHOP.'/db_names.php');
require_once('library/settings_class.php');
global $sql, $tp;
// Select all the active products
$sql->db_Select($e107shop_db_name["settings"], "currency_symbol", "");
while($row = $sql -> db_Fetch()){
    $currency_symbol = $row['currency_symbol'];
}
$sql -> db_Select_gen("SELECT * FROM #".$e107shop_db_name["products"]." left join #".$e107shop_db_name["category_matrix"]." on product_id = ID WHERE active = 1 order by RAND() LIMIT 0, 1", FALSE);
while($row = $sql -> db_Fetch()){
    $itemname = $row["product_name"];
    $itemid = $row["ID"];
    $price = $row["special_price"];
    $price1 = $row["product_price"];
    $Desc = $row["description"];
    $smallpic = $row["small_image"];
    $bigpic = $row["large_image"];
    $catid = $row["category_id"];
}
if ($price == "") $price = $price1; // if there is no special price, use normal price
if ($bigpic == "") $bigpic = 'noimgbig.jpg'; // set default picture if there is none
$piclink = e_PLUGIN.E107SHOP."/product_details.php?product=".$itemid."&amp;cat=".$catid;
$buylink = e_PLUGIN.E107SHOP."/cart.php?action=add&amp;product=".$itemid."&amp;cat=".$catid."&amp;quantity=1";
$max2 = "75";
$post = "...[ <a href='".$piclink."'>".lan_global_more."</a> ]";
$itemDesc = $tp->text_truncate($Desc,$max2,$post);
$itemDesc = str_replace("[html]", "", $itemDesc);
$itemDesc = str_replace("[/html]", "", $itemDesc);
$itemlink = e_IMAGE_ABS."thumb.php?".e_PLUGIN.E107SHOP."/images/products/".$bigpic."+100+noscale";
$text = "
<div style='width: 100%;'>
<table>
    <tr>
        <td class='forumheader3' style='text-align: center;'>
            <b>$itemname</b>
        </td>
    </tr>
    <tr>
        <td class='forumheader3' style='text-align: center;'>
            <a href='$piclink'><img style='border: none;' src='$itemlink' title='".lan_global_information."' alt='' /></a>
        </td>
    </tr>
    <tr>
        <td class='forumheader3' style='text-align: center;'>
            <b style='font-size: 14pt;'>".lan_global_price.":</b> ".$currency_symbol.e107shop_get_numformat($price)."
        </td>
    </tr>
    <tr>
        <td class='forumheader3'>
            ".$tp->toHTML($itemDesc, TRUE)."<br />
        </td>
    </tr>
    <tr>
        <td style='text-align: center;'>
            <input class='button' type='button' value='".lan_global_buy."' onclick='window.location.href=\"".$buylink."\"' />
        </td>
    </tr>
</table>
</div>";
// You can set all the translated text used here in the language file around line 50
$caption = lan_global_random_products;
$ns -> tablerender($caption, $text, 'rand');
